(function (vc, vm) {

    vc.extends({
        data: {
            editProductGroupInfo: {
                groupId: '',
                prodName: '',
                productId: '',
                valueId: '',
                prodDesc: '',
                userCount: '',
                groupPrice: '',
                state: '',
                startTime: '',
                endTime: '',
                rebateFlag: '',
                rebate: 0,
            }
        },
        _initMethod: function () {

            vc.initDate('editProductGroupStartTime',function(_time){
                $that.editProductGroupInfo.startTime = _time;
            });
            vc.initDate('editProductGroupEndTime',function(_time){
                $that.editProductGroupInfo.endTime = _time;
            })

        },
        _initEvent: function () {
            vc.on('editProductGroup', 'openEditProductGroupModal', function (_params) {
                $that.refreshEditProductGroupInfo();
                $('#editProductGroupModel').modal('show');
                vc.copyObject(_params, $that.editProductGroupInfo);
                $that.editProductGroupInfo.shopId = vc.getCurrentCommunity().shopId;
              
            });
        },
        methods: {
            editProductGroupValidate: function () {
                return vc.validate.validate({
                    editProductGroupInfo: $that.editProductGroupInfo
                }, {
                    'editProductGroupInfo.prodName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "产品名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "产品名称不能超过128"
                        },
                    ],
                    'editProductGroupInfo.productId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "产品ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "产品ID不能超过30"
                        },
                    ],
                    'editProductGroupInfo.valueId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "规格值不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "规格值不能超过30"
                        },
                    ],
                    'editProductGroupInfo.prodDesc': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "团购产品简介不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "256",
                            errInfo: "团购产品简介不能超过256"
                        },
                    ],
                    'editProductGroupInfo.userCount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "拼团人数不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "拼团人数不能超过30"
                        },
                    ],
                    'editProductGroupInfo.groupPrice': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "拼团金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "拼团金额不能超过30"
                        },
                    ],
                    'editProductGroupInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "状态不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "状态不能超过12"
                        },
                    ],
                    'editProductGroupInfo.startTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "开始时间不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "开始时间不能超过30"
                        },
                    ],
                    'editProductGroupInfo.endTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "结束时间不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "结束时间不能超过30"
                        },
                    ],
                    'editProductGroupInfo.rebateFlag': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "是否返佣不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "是否返佣不能超过12"
                        },
                    ],
                    'editProductGroupInfo.rebate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "团长返佣不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "团长返佣不能超过30"
                        },
                    ],
                    'editProductGroupInfo.groupId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "编号不能为空"
                        }]

                });
            },
            editProductGroup: function () {
                if (!$that.editProductGroupValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/productGroup.updateProductGroup',
                    JSON.stringify($that.editProductGroupInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editProductGroupModel').modal('hide');
                            vc.emit('productGroupManage', 'listProductGroup', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditProductGroupInfo: function () {
                $that.editProductGroupInfo = {
                    groupId: '',
                    prodName: '',
                    productId: '',
                    valueId: '',
                    prodDesc: '',
                    userCount: '',
                    groupPrice: '',
                    state: '',
                    startTime: '',
                    endTime: '',
                    rebateFlag: '',
                    rebate: 0,
                }
            },
            
        }
    });

})(window.vc, window.vc.component);
